use std::ops::Neg;

fn main() {
    let mut x = 5;

    println!("Some x has {}, addres {:p} ", x, &x);
    x = 6;
    println!("Some x has {}, addres {:p}", x, &x);

    let space = " ";
    let space = space.len();
    println!("Затенения строки целочистенным {}", space);

    let a = 5;
    let a = a as f32 * 1.2;
    println!("Преобразование инта в флоат {}", a);

    let turple: (i32, f64, u8) = (500, 6.4, 1);
    println!("Кортежы {} {} {}", turple.0, turple.1, turple.2);

    let massive: [i32; 5] = [1, 2, 3, 4, 5];
    println!("Массивы {}", massive[3]);

    println!("function {}", another_function(2));

    //ИФ
    if another_function(2) < 40 {
        println!("Щначение истинно!");
    } else {
        println!("Значение ложно!");
    }

    //ИФ ЕЛСЕ
    let number = 6;

    if number % 4 == 0 {
        println!("число делится на 4");
    } else if number % 3 == 0 {
        println!("число делится на 3");
    } else if number % 2 == 0 {
        println!("число делится на 2");
    } else {
        println!("число не делится на 4, 3 и 2");
    }

    //задаем значение числа чере ИФ
    let condition = true;
    let number_1 = if condition { 5 } else { 6 };
    println!("some {}", number_1);

    //бесконечный цикл, выход черех бреак
    let mut counter = 0;
    let result = loop {
        counter += 1;
        if counter == 3 {
            break counter * 1;
        }
    };
    println!("loop {}", result);

    //цикл ВАЙЛ
    while counter != 0 {
        println!("{}!", counter);
        counter = counter - 1;
    }
    println!("Поехали!!!");

    //цикл ФОР
    let a = [10, 20, 30, 40, 50];
    for element in a.iter() {
        println!("Значение равно {}", element);
    }

    farh();
    finn();

    let s1 = String::from("hello");
    //let s2 = s1; //не работает потому что s1 удаленно
    let s2 = s1.clone(); //глубокое клонирование, из-за неизвестнного объема данных
    println!("{}, world! {}!", s1, s2);

    let x13 = 5;
    let y13 = x13; //клонирование без глубогоко так размер данных извествен
    println!("x={} y={}", x13, y13);

    //Структура
/*    struct User {
        username: String,
        email: String,
        sign_in_count: u64,
        active: bool,
    }

    let mut user1 = User {
        email: String::from("someone@example.com"),
        username: String::from("someusername123"),
        active: true,
        sign_in_count: 1,
    };
    println!("{}", user1.email);
    user1.email = String::from("anotheremaill@example.com");
    println!("{}", user1.email);
*/
let usef = build_user("newmail@mail.cum".to_string(), "Vasya".to_string());
println!("{}", usef.email);

    }

struct User {
        username: String,
        email: String,
        sign_in_count: u64,
        active: bool,
    }


fn build_user(email: String, username: String) -> User {
    User{
        email,
        username,
        active: true,
        sign_in_count: 1,
    }
}

fn another_function(o: i32) -> i32 {
    21 * o
}

fn farh() {
    convert_fahr(315.0);
    convert_cels(315.0);
}

fn convert_fahr(x: f32) {
    let mut fahr: f32 = 0.0;

    while x >= fahr {
        let celsius = (5.0 / 9.0) * (fahr - 32.0);

        println!("cels - {}, fahr - {}", celsius, fahr);

        fahr += 45.0;
    }
}

fn convert_cels(x: f32) {
    let mut cels = 0.0;

    while x >= cels {
        let fahr = ((9.0 / 5.0) * cels) + 32.0;

        println!("cels - {}, fahr - {}", cels, fahr);

        cels += 45.0;
    }
}

fn finn() {
    let num = 4;

    if num >= 2 {
        finn_plus(num);
    } else if num < 0 {
        finn_neg(num);
    } else {
        println!("y {} num 1", num);
    }
}

fn finn_plus(x: i32) {
    //let mut num = 1;
    let mut num_f = 0;
    let mut num_0 = 1;
    let mut num_1 = 0;

    for y in 1..(x + 1) {
        let num = num_0 + num_1;
        num_0 = num;
        num_1 = num_f;
        num_f = num;
        println!("y {}, num {}", y, num);
    }
}

fn finn_neg(x: i32) {
    //let mut num = 1;
    let mut num_f = 0;
    let mut num_0 = 1;
    let mut num_1 = 0;

    for y in 1..(x - 1).neg() {
        let num = num_1 - num_0;
        num_0 = num;
        num_1 = num_f;
        num_f = num;
        println!("y {}, num {}", y.neg(), num.neg());
    }
}
